
$(document).ready(function(){
	$(".addPlan").prepend('<i class="layui-icon layui-icon-add-1" style="font-size: 16px; color: #186FF2;"></i>');
});

/* 默认展开 展开一个,其他同级的不合并 */
$(".headline").each(function(){
	$(this).next(".collapse").collapse('show');
	$(this).find(".headline-status img").attr("src","img/minus.png");
})
$(".headline").on("click",function(){
	if($(this).next(".collapse").is(":hidden")){
		$(this).next(".collapse").css({"display":"block"})
		$(this).next(".collapse").collapse('toggle');
		$(this).find(".headline-status img").attr("src","img/minus.png");
	}else{
		$(this).next(".collapse").css({"display":"none"})
		$(this).next(".collapse").collapse('toggle');
		$(this).find(".headline-status img").attr("src","img/add.png");
	}
})

$(".stepheadline").each(function(){
	$(this).next(".collapse").collapse('show');
	$(this).find(".stepheadline-status img").attr("src","img/minus.png");
	// $(this).find(".step-open-close").text("收起");
})
$(".stepheadline").on("click",function(){
	if($(this).next(".collapse").is(":hidden")){
		$(this).next(".collapse").css({"display":"block"})
		$(this).next(".collapse").collapse('toggle');
		$(this).find(".stepheadline-status img").attr("src","img/minus.png");
		// $(this).find(".step-open-close").text("收起");
	}else{
		$(this).next(".collapse").css({"display":"none"})
		$(this).next(".collapse").collapse('toggle');
		$(this).find(".stepheadline-status img").attr("src","img/add.png");
		// $(this).find(".step-open-close").text("展开");
	}
})

//添加维修计划提醒
var arr = window.location.pathname.split("/");
var urlFilename = arr[arr.length - 1].substring(0, arr[arr.length - 1].lastIndexOf("."))
var dmc = urlFilename.substring(0, urlFilename.indexOf("_"));
function addPlan(obj){
	var taskIdent = $($(obj)).parent().parent().attr("id");
	var title = $($(obj)).parent().parent().find(".taskTitle").eq(0).text();
	var descript = $($(obj)).parent().parent().find(".taskDescr").eq(0).text();
	parent.addMaintenancePlan(dmc,taskIdent,title,descript);
}

//初始化维修计划，显示下次执行维修计划时间
initPlan();
function initPlan(){
	$.ajax({
		type: "GET",
		url: baseApi + "padMaintenancePlan/getPlansByUidAndDmc?t=" + (new Date()).getTime(),
		data: {
			"uid": sessionStorage.getItem("user"),
			"dmc": dmc
		},
		dataType: "JSON",
		success: function (res) {
			if (res.resp_msg == "请求成功！") {
				console.log(res.datas);
				var plans = res.datas;
				for(var i = 0;i < plans.length; i++){
					if(plans[i].taskIdent != null && plans[i].taskIdent != ""){
						$("#" + plans[i].taskIdent).find(".nextPlan").eq(0).text(i18n("i18n-lan-next") + plans[i].executionTime);
						$("#" + plans[i].taskIdent).find(".addPlan").eq(0).attr("disabled","disabled");
					}
				}
			}
		}
	})
}

//跳转到对应维修计划位置
toTaskIdent();
function toTaskIdent(){
	var taskIdent = sessionStorage.getItem("taskIdent");
	if(taskIdent != null && taskIdent != ""){
		sessionStorage.setItem("taskIdent",null);
		$("#" + taskIdent).css("border","solid red 1px");
		location.href = "#" + taskIdent;
	}
}
